<template>
    <div>
        <!-- 根据时间 显示 广告投放进度条进度 -->
        <el-progress :percentage="percentage" :color="customColors"></el-progress>
    </div>
</template>

<script>
export default { 
  components: {},
  props: {
    "adverte":{
      type: Object,
      default: undefined,
    }
  },
  data() {
     return {
        //percentage: 20,
        customColors: [
          {color: '#f56c6c', percentage: 20},
          {color: '#e6a23c', percentage: 40},
          {color: '#5cb87a', percentage: 60},
          {color: '#1989fa', percentage: 80},
          {color: '#6f7ad3', percentage: 100}
        ] 
     }
  },
  computed:{
    percentage(){
     // =1 表示 设置过结束时间
        let hasendtime = this.adverte.hasendtime;
        let days = 365;
        let hasdays = 0;
        let  startDate = Date.parse(this.adverte.startday);
        let  endDate = Date.parse(this.adverte.endday);
        let  nowDate = new Date().getTime();
        //   endday, endtime,startday,starttime
        if(hasendtime ==1){
            //  * @param dateString1  开始日期 yyyy-MM-dd
            //  * @param dateString2  结束日期 yyyy-MM-dd
        
            if(startDate < endDate){
                days = (endDate - startDate)/(1*24*60*60*1000);
            }else if(startDate == endDate) {
                days = 1;
            }else{
                days = 1;
            }
        }
        //已经开始了几天
        if( startDate < nowDate){
            hasdays = (nowDate - startDate)/(1*24*60*60*1000);
        }
        // console.log(hasdays,days,startDate ,nowDate);
        let per = 0;
        if( Math.round(hasdays *100 / days) <1){
             per = Math.round((hasdays *10000 / days))/100;
        }else{
             per = Math.round((hasdays *100  / days)) ;
        }
        
        if(per >99 && days ==365){
            per = 99;
        }
        
        return per;
    }
  },
  methods: {
    
  }
}
</script>